import service from '@/utils/request'


export const login = (params) => { // 登陆
  return new Promise((resolve,reject)=>{
    service.post('/login/boss',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}



export const getGreenEnergyList = (params) => { // 获取绿色能量列表
  return new Promise((resolve,reject)=>{
    service.post('/boss/greenEnergy/listManager',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getUserList = (params) => { // 获取用户列表
  return new Promise((resolve,reject)=>{
    service.post('/boss/userCharacter/listManager',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getRoleList = (params) => { // 获取角色列表
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/listManager',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const addRole = (params) => { // 新增角色
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/insert',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const editRole = (params) => { // 编辑角色
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/update',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const delRole = (roleId) => { // 删除角色
  return new Promise((resolve,reject)=>{
    service.get(`boss/role/delete/${roleId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getRoleDetail = (roleId) => { // 获取角色详情
  return new Promise((resolve,reject)=>{
    service.get(`/boss/role/get/${roleId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getroleForUsers = (params) => { // 
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/listRoleUser',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAuthTree = () => { // 获权限树
  return new Promise((resolve,reject)=>{
    service.get('/boss/permission/rootTree')
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAccountList = (params) => { // 获取帐号列表
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/listManager',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const addAccount = (params) => { // 添加帐号
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/insert',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const editAccount = (params) => { // 编辑帐号
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/update',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAccountDetail = (userId) => { // 获取帐号详情
  return new Promise((resolve,reject)=>{
    service.get(`/boss/account/get/${userId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const delAccount = (params) => { // 删除角色
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/delete',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getRSAPublicKey = () => { // 获取RSA公钥
  return new Promise((resolve,reject)=>{
    service.get('/rsa/publicKey')
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const decryptRSA = (data)=>{ // Rsa解密
  return new Promise((resolve,reject)=>{
    service.get(`/rsa/decrypt/?message=${encodeURIComponent(data)}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getloginlog = (params) => { // 登陆日志
  return new Promise((resolve,reject)=>{
    service.post('/boss/log/login/list',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getOperatelog = (params) => { // 操作日志
  return new Promise((resolve,reject)=>{
    service.post('/boss/log/operation/list',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getUserInfo = () => { //获取登录信息
  return new Promise((resolve,reject)=>{
    service.get('/getManagerUserInfo')
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const greenEnergyExportAll = () => { //绿色能量导出全部
  return new Promise((resolve,reject)=>{
    // service.get('/boss/greenEnergy/export')
    // .then(res=>{
    //   resolve(res.data) 
    // })
    service({
      url: '/boss/greenEnergy/export',
      method: 'get',
      //定义类型
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },     
      responseType:'blob', 
    }).then(res=>{
         resolve(res.data) 
    })
  })
}




